<!DOCTYPE html>
<html>
<head>
    <title>API</title>

    <link href="../../content/shared/styles/examples-offline.css" rel="stylesheet">
    <link href="../../../styles/kendo.common.min.css" rel="stylesheet">
    <link href="../../../styles/kendo.default.min.css" rel="stylesheet">

    <script src="../../../js/jquery.min.js"></script>
    <script src="../../../js/kendo.web.min.js"></script>
    <script src="../../content/shared/js/console.js"></script>
    <script>
        
    </script>
    
    
</head>
<body>
    
        <a class="offline-button" href="../index.html">Back</a>
    
    
        <div id="example" class="k-content">

            <div class="configuration" style="width:190px">
                <span class="configHead">API Functions</span>
                <ul class="options">
                    <li>
                        <input type="text" value="0" id="selectRow" class="k-textbox"/>
                        <button class="selectRow k-button">Select row</button>
                    </li>
                    <li>
                        <button class="clearSelection k-button">Clear selected rows</button>
                    </li>
                    <li>
                        <input type="text" value="0" id="groupRow" class="k-textbox"/>
                        <button class="toggleGroup k-button">Collapse/Expand group</button>
                    </li>
                </ul>
            </div>

            <div id="grid" style="width:500px;"></div>

            <script>
                $(document).ready(function () {
                    $("#grid").kendoGrid({
                        dataSource: {
                            transport: {
                                read: {
                                    url: "http://demos.kendoui.com/service/Products",
                                    dataType: "jsonp"
                                }
                            },
                            pageSize: 5,
                            group: {
                                field: "UnitsInStock",
                                dir: "asc"
                            }
                        },
                        selectable: "multiple row",
                        pageable: {
                            buttonCount: 5
                        },
                        scrollable: false,
                        groupable: true,
                        columns: [
                            {
                                field: "ProductName",
                                title: "Product Name"
                            },
                            {
                                field: "UnitPrice",
                                title: "Unit Price",
                                format: "{0:c}"
                            },
                            {
                                field: "UnitsInStock",
                                title: "Units In Stock"
                            }
                        ]
                    });

                    $(".clearSelection").click(function () {
                        $("#grid").data("kendoGrid").clearSelection();
                    });

                    var selectRow = function (e) {
                        if (e.type != "keypress" || kendo.keys.ENTER == e.keyCode) {
                            var grid = $("#grid").data("kendoGrid"),
                                    rowIndex = $("#selectRow").val(),
                                    row = grid.tbody.find(">tr:not(.k-grouping-row)").eq(rowIndex);

                            grid.select(row);
                        }
                    },
                        toggleGroup = function (e) {
                            if (e.type != "keypress" || kendo.keys.ENTER == e.keyCode) {
                                var grid = $("#grid").data("kendoGrid"),
                                    rowIndex = $("#groupRow").val(),
                                    row = grid.tbody.find(">tr.k-grouping-row").eq(rowIndex);

                                if (row.has(".k-i-collapse").length) {
                                    grid.collapseGroup(row);
                                } else {
                                    grid.expandGroup(row);
                                }
                            }
                        };


                    $(".selectRow").click(selectRow);
                    $("#selectRow").keypress(selectRow);

                    $(".toggleGroup").click(toggleGroup);
                    $("#groupRow").keypress(toggleGroup);
                });
            </script>

            <style scoped>
                .configuration .k-textbox
                {
                    width: 23px;
                }
            </style>

        </div>

</body>
</html>
